package com.mapreduce.mapjoin;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class DistributedCacheDriver {

    public static void main(String[] args) throws IOException, URISyntaxException, ClassNotFoundException, InterruptedException {

        // 1 获取配置信息，或者job对象实例
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration);

        // 2 指定本程序的jar包所在的本地路径
        job.setJarByClass(DistributedCacheDriver.class);

        // 3 关联map
        job.setMapperClass(DistributedMapper.class);


        // 4 设置最终输出数据类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);
        //不需要Reduce，设置为0
        job.setNumReduceTasks(0);
        // 6 加载缓存数据
        job.addCacheFile(new URI("file:///D:/wordcount/input/joincache/pd.txt"));
        // Map端Join的逻辑不需要Reduce阶段，设置reduceTask数量为0

        // 指定job的输入原始文件所在目录
        FileInputFormat.setInputPaths(job, new Path("D:\\wordcount\\input\\order.txt"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\wordcount\\output\\wc109"));

        // 将job中配置的相关参数，以及job所用的java类所在的jar包， 提交给yarn去运行
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);


    }

}
